<template>
    <van-pull-refresh 
        v-model="isLoading" 
        @refresh="onRefresh"
    >   
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
        > 
            <slot></slot>
        </van-list>
    </van-pull-refresh>
</template>

<script>
export default {
    data(){
        return {
            isLoading:false, // 判断是否正在刷新
            loading:false ,  // 是否正在加载更多
            finished:false, // 数据已经全部请求

        }   
    },
    props:[
        'refresh',
        'getMoreData'
    ],
    methods:{
        // 下拉刷新 
        onRefresh(){
            this.refresh()
            this.isLoading = true;
            this.$toast("下拉刷新成功")
            setTimeout(() => {
                this.isLoading = false;
            }, 500);
        },
        // 加载更多 
        onLoad(){
            this.loading = true;
            setTimeout(() => {
                this.getMoreData(
                    ()=>{
                    this.loading = false;
                    this.$toast('加载更多成功')
                },()=>{
                    this.finished = true;
                    this.$toast('没有更多数据了')
                })
            }, 500);
        }
    }
}
</script>